package com.example.onlinemusic.config;

import com.example.onlinemusic.model.Contant;
import com.example.onlinemusic.tools.ResponseBodyMessage;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:配置自定义拦截器
 * User: hold on
 * Date: 2022-08-06
 * Time: 0:43
 */
@Configuration
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //检查是否登入!
        HttpSession session = request.getSession(false);
        if(session==null||session.getAttribute(Contant.USERINFO_SESSION_KEY)==null){
            //未登入状态!
            System.out.println("未登入");
            return false;
        }
        return true;
    }
}
